package com.bookhouse.service.impl;

import java.util.List;

import com.bookhouse.dao.BookDao;
import com.bookhouse.domain.Book;
import com.bookhouse.service.BookService;

public class BookServiceImpl implements BookService {

	BookDao bookDao;

	public void setBookDao(BookDao bookDao) {
		this.bookDao = bookDao;
	}

	@Override
	public void saveBook(Book book) {
		if (book.getId() != null && book.getId() > 0)
			bookDao.update(book);
		else
			bookDao.save(book);
	}

	@Override
	public List<Book> getAllBook() {
		return bookDao.findAll(Book.class);
	}

	@Override
	public Book getBook(int id) {
		return bookDao.get(Book.class, id);
	}

	@Override
	public void deleteBook(int id) {
		bookDao.delete(Book.class, id);
	}

    @Override
    public List<Book> getSearchBook(String sql) {
        return bookDao.find(sql);
    }

}
